using System;
using System.Collections.Generic;
using System.IO;
using System.ComponentModel.DataAnnotations.Schema;

namespace FileManager.Models
{
    public class FileItem
    {
        public int Id { get; set; }
        public string FilePath { get; set; }
        public string FileName { get; set; }
        public string FileType { get; set; }
        public string Extension { get; set; }
        public long FileSize { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime LastAccessTime { get; set; }
        public DateTime CreateIndexTime { get; set; } = DateTime.Now;
        public bool IsEncrypted { get; set; }
        public string HashValue { get; set; }
        public bool IsImportant { get; set; }
        public string Remark { get; set; }
        
        [InverseProperty("File")]
        public List<FileChatRelation> ChatRelations { get; set; } = new List<FileChatRelation>();
        
        [InverseProperty("File")]
        public List<FileTagRelation> FileTagRelations { get; set; } = new List<FileTagRelation>();

        public FileItem() {}

        public FileItem(string filePath)
        {
            FilePath = filePath;
            var fileInfo = new FileInfo(filePath);
            FileName = fileInfo.Name;
            FileSize = fileInfo.Length;
            CreateTime = fileInfo.CreationTime;
            LastAccessTime = fileInfo.LastAccessTime;
            Extension = fileInfo.Extension;
        }
    }
}